package com.itheima.demo7;

import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class MyThreadPoolDemo {
    public static void main(String[] args) throws InterruptedException {

        //1.获取线程池
        ExecutorService pool1 = Executors.newCachedThreadPool();//无上限的线程池
        ExecutorService pool2 = Executors.newFixedThreadPool(3);//自己设置线程池的线程上限

        //2.提交任务
        Thread.sleep(100);
        pool2.submit(new MyRunnable());
        Thread.sleep(100);
        pool2.submit(new MyRunnable());
        Thread.sleep(100);
        pool2.submit(new MyRunnable());
        Thread.sleep(100);
        pool2.submit(new MyRunnable());
        Thread.sleep(100);
        pool2.submit(new MyRunnable());

        //3.销毁线程池
//        pool1.shutdown();
    }
}
